package com.cyx.system.utils;

import lombok.Data;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Data
public class BCryptUtils {

    private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    /**
     *  加密算法
     * @param password 用户输入的密码
     * @return
     */
    public static String encode(String password) {
        return passwordEncoder.encode(password);
    }

    /**
     *
     * @param rawPassword 真实密码 用户输入的密码
     * @param encodedPassword 加密算法加密过的密码
     * @return
     */
    public static boolean matches(String rawPassword, String encodedPassword) {
        return passwordEncoder.matches(rawPassword, encodedPassword);
    }

    public static void main(String[] args) {
        System.out.println(encode("123456"));
        System.out.println(matches("123456", "$2a$10$fmRpy5mBG8.IO3dij5uHzegvC7R2ArZAu5NtreoxzqJMKMpnAKuUi"));
    }

}
